package com.travel.server.manager.impl.command.adversiting;

import com.travel.common.util.CollectionUtil;
import com.travel.server.manager.dto.request.EmptyRequest;
import com.travel.server.manager.dto.response.advertising.QueryAdvertisingPositionEnumResponse;
import com.travel.server.manager.dto.response.advertising.QueryAdvertisingPositionEnumResponse.PositionEnumItem;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.dal.PageDto;
import com.travel.server.manager.impl.dal.PositionDal;
import com.travel.server.manager.model.AdvertisingPositionInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: LiZhenhui
 * @Date: 2018/12/20 15:28
 * @Desc:
 */
@Component
public class QueryAdvertisingPositionEnumCommand extends AbstractCommand<EmptyRequest, QueryAdvertisingPositionEnumResponse> {

    @Autowired
    private PositionDal positionDal;

    @Override
    protected void checkInput(EmptyRequest request) {

    }

    @Override
    public QueryAdvertisingPositionEnumResponse handle(EmptyRequest request) {
        QueryAdvertisingPositionEnumResponse response = new QueryAdvertisingPositionEnumResponse();
        List<PositionEnumItem> enumList = new ArrayList<>();
        PageDto<AdvertisingPositionInfo> pageDto = positionDal.selectByPage(null, null);
        List<AdvertisingPositionInfo> list = pageDto.getList();
        if(!CollectionUtil.isEmpty(list)){
            for(AdvertisingPositionInfo info : list){
                PositionEnumItem item = new PositionEnumItem();
                item.setId(info.getId());
                item.setName(info.getPositionName());
                enumList.add(item);
            }
        }
        response.setEnumList(enumList);
        return response;
    }
}
